package service;

import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
//将类交由Spring容器进行管理
@Component
//表明该类是切面控制类
@Aspect
public class TransactionManagerHandler {
    @Pointcut("execution(public void service.impl.UserServiceImpl.insert())")
    public void pointcut(){}

    @Before("pointcut()")
    public void begin() {
        System.out.println("开启事务！");
    }

    @AfterReturning("pointcut()")
    public void commit() {
        System.out.println("提交事务！");
    }

    @AfterThrowing("pointcut()")
    public void rollback() {
        System.out.println("回滚事务！");
    }

    @After("pointcut()")
    public void closeSession() {
        System.out.println("关闭链接！");
    }
}
